package com.itmaster.domain.model;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Fernando Perez
 */
public class UsersRepository {

	protected static final String USERNAME_2 = "username3";
	protected static final String USERNAME_1 = "username2";
	protected static final String USERNAME_0 = "username1";
	private static UsersRepository instance = new UsersRepository();
	private final List<User> users = new ArrayList<User>();

	/**
	 * Private constructor to avoid instantiation
	 */
	private UsersRepository() {
		initialize();
	}

	/**
	 * Singleton
	 * 
	 * @return {@link UsersRepository}
	 */
	public static UsersRepository getInstance() {
		return instance;
	}

	/**
	 * @param username
	 * @return
	 */
	public User findUniqueByUsername(String username) {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		for (User user : users) {
			if (user.getUsername().equals(username)) {
				return user;
			}
		}

		return null;
	}

	/**
	 * 
	 */
	private void initialize() {
		users.add(new User(USERNAME_0, USERNAME_0));
		users.add(new User(USERNAME_1, USERNAME_1));
		users.add(new User(USERNAME_2, USERNAME_2));
	}

}